import uuid
from enum import Enum, unique

from django.db import models

from warehouse.models import JuqiGood
from wxcloudrun.models import BaseModel
from wxuser.models import Users, UserOrder


@unique
class UserPackageGoodsState(models.IntegerChoices):
    unhandled = 0  # 未处理状态
    refined = 1  # 已提炼状态
    delivery = 2  # 已发货状态
    lock = 3  # 已上保险状态


class UserPackageGoods(BaseModel):
    user_uuid = models.UUIDField()

    good_uuid = models.UUIDField()

    good_level_title = models.CharField(verbose_name="赏品等级，ABCD", max_length=200)

    game_type = models.PositiveIntegerField(verbose_name="游戏类型")

    game_uuid = models.UUIDField(verbose_name="游戏uuid")

    game_son_uuid = models.UUIDField(null=True)

    game_box_num = models.IntegerField(default=0)

    order_uuid = models.UUIDField()

    order_num = models.PositiveIntegerField(default=0, verbose_name="第几发抽取")

    state = models.PositiveIntegerField(
        default=UserPackageGoodsState.unhandled,
        verbose_name="物品状态",
        choices=UserPackageGoodsState.choices,
    )

    class Meta:
        db_table = "UserPackageGoods"  # 数据库表名
        indexes = [
            models.Index(fields=["uuid"]),
            models.Index(fields=["deleted"]),
            models.Index(fields=["createdAt"]),
            models.Index(fields=["order_uuid"]),
            models.Index(fields=["user_uuid"]),
            models.Index(fields=["good_uuid"]),
            models.Index(fields=["good_level_title"]),
            models.Index(fields=["game_uuid"]),
            models.Index(fields=["game_son_uuid"]),
            models.Index(fields=["game_box_num"]),
            models.Index(fields=["game_type"]),
            models.Index(fields=["state"]),
            models.Index(fields=["order_num"]),
        ]
        ordering = ["-createdAt"]
